﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace _14.action
{
    class Program
    {
        static void Main(string[] args)
        {
            { // Task
                Action a = () => Console.WriteLine("hehe");
                //a(); //ok
                //a.Invoke(); //ok
                a.DynamicInvoke(); //ok

                Action<int> a2 = (i) => Console.WriteLine(i);
                a2(1);

                //最多可以有16个参数
                Action<int, int, string> a3 = (i1, i2, s) => Console.WriteLine("{0}, {1}, {2}", i1, i2, s);
                a3(1, 5, "hooooooooohoh");

                //更简洁的写法
                void a4(int i) => Console.WriteLine(++i);
                a4(100);
            }

            Console.WriteLine("--------");

            { // Func
                Func<int> f1 = () => 100;
                int r = f1();
                Console.WriteLine(r);

                r = f1.Invoke();
                Console.WriteLine(r);

                r = (int)f1.DynamicInvoke(); //注意，需要转换类型，默认object
                Console.WriteLine(r);

                Func<string, int> f2 = s => int.Parse(s); //最多16个参数，最后一个是返回值类型
                r = f2("123");
                Console.WriteLine(r);
            }

            Console.ReadKey();
        }
    }
}
